import { z } from 'zod'

import { baseManyObjectsScheme, baseScheme } from '@/types/base.types'

import { dayjsStrValidator, dayjsValidator } from '@/utils/customValidators'

export const taskStatuses: { [index: number]: string } = {
	0: 'Создана',
	1: 'Выполняется',
	8: 'Отменена',
	9: 'Завершена'
}

export const taskScheme = baseScheme.extend({
	title: z.string(),
	description: z.string(),
	status: z.number().min(0).max(9),
	deadline: dayjsStrValidator.nullable(),

	creator: z.number(),
	executor: z.number().nullable(),

	request: z.number().nullable(),
	order: z.number().nullable()
})

export type ITask = z.infer<typeof taskScheme>

export const taskFormScheme = taskScheme
	.omit({
		created_on: true,
		updated_on: true,
		creator: true,
		executor: true,
		deadline: true
	})
	.extend({
		deadline: dayjsValidator.nullable()
	})

export type ITaskForm = z.infer<typeof taskFormScheme>

export const tasksScheme = baseManyObjectsScheme.extend({
	results: z.array(taskScheme)
})

export type ITasks = z.infer<typeof tasksScheme>
